home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Dr. Windows 3
/
dr win3.zip
/
dr win3
/
PROGRAMR
/
CENVIW1.ZIP
/
PICKFILE.LIB
< prev
next >
Wrap
Text File
|
1993-08-05
|
3KB
|
60 lines
// PickFile.lib - Cmm code wrapper for a simple implementation of the
// GetOpenFileName() function found in the Windows
// Common Dialog DLL. You may #include this file in
// your CMM source to have access to this version of
// GetOpenFileName().
// GetOpenFileName([MatchingFileSpec[,Title]])
// MatchingFileSpec: string file specification, including wildcard in the
// file name. For example "C:\\WIN\\*.TXT" or
// "*.INI". If this is not supplied or if it is
// NULL then *.* will be the default.
// Title: String to be the title of the open dialog box, if this is NULL
// then Windows defaults to "Open".
// Return: Return a string that is the full file specification of the
// file selected, or NULL if no file was selected.
GetOpenFileName(MatchingFileSpec,Title)
{
// The OpenFileName structure is very large, but most of its fields are
// are not used, so will set it all to zero except the few fields needed.
#define OFN_MAX_FILESPECLEN 200
#define OFN_SIZE 72
#define OFN_FILENAME_OFFSET 24
#define OFN_INIT_DIR_OFFSET 40
#define OFN_TITLE_OFFSET 44
BLObSize(ofn,OFN_SIZE);
memset(ofn,0,OFN_SIZE);
BLObPut(ofn,0,OFN_SIZE,UWORD32);
BLObPut(ofn,4,ScreenHandle(),UWORD16);
BLObPut(ofn,6,Instance(),UWORD16);
// if a title was supplied, then use it
if ( 1 < va_arg() && NULL != Title ) {
BLObPut(ofn,OFN_TITLE_OFFSET,pointer(Title),UWORD32);
}
// if filename was not supplied, then default to wildcard
if ( 0 < va_arg() && NULL != MatchingFileSpec ) {
strcpy(ofn_spec,MatchingFileSpec);
} else {
strcpy(ofn_spec,"*.*");
}
ofn_parts = SplitFileName(ofn_spec);
// store the dir part of the filename (without extra backslash)
ofn_dir = FullPath(ofn_parts.dir);
if ( ofn_dir[strlen(ofn_dir)-1] == '\\' && strcmp(ofn_dir+1,":\\") )
ofn_dir[strlen(ofn_dir)-1] = 0;
BLObPut(ofn,OFN_INIT_DIR_OFFSET,pointer(ofn_dir),UWORD32);
// set filename part of the filename, and also initialize it
memset(ofn_name,0,OFN_MAX_FILESPECLEN);
strcat(strcpy(ofn_name,ofn_parts.name),ofn_parts.ext);
BLObPut(ofn,OFN_FILENAME_OFFSET,pointer(ofn_name),UWORD32);
BLObPut(ofn,OFN_FILENAME_OFFSET+4,OFN_MAX_FILESPECLEN-1,UWORD32);
return( DynamicLink("COMMDLG.DLL","GETOPENFILENAME",SWORD16,PASCAL,ofn)
? ofn_name : NULL );
}